import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/login'),
        meta: { title: '登录' },
        hidden: true
    },

    {
        path: '/404',
        component: () =>
            import ('@/views/404'),
        meta: { title: '404' },
        hidden: true
    },

    {
        path: '/',
        name: '/',
        component: Layout,
        redirect: '/index',
        meta: { title: '首页' },
        children: [{
            path: 'index',
            name: 'index',
            component: () =>
                import ('@/views/index/index'),
            meta: { title: '首页', icon: 'dashboard' }
        }]
    },

    // 会员管理
    {
        path: '/vip',
        component: Layout,
        redirect: '/vip/members',
        name: 'vip',
        meta: { title: '会员管理', icon: 'example' },
        children: [{
                path: 'members',
                name: 'vipMembers',
                component: () =>
                    import ('../views/vip/vip-members.vue'),
                meta: { title: '会员信息', icon: 'example' }
            },
            {
                path: 'complaint',
                name: 'vipComplaint',
                component: () =>
                    import ('../views/vip/vip-complaint.vue'),
                meta: { title: '举报信息', icon: 'example' }
            },
            {
                path: 'recommend',
                name: 'vipRecommend',
                component: () =>
                    import ('../views/vip/vip-recommend.vue'),
                meta: { title: '推荐管理', icon: 'example' }
            },
            {
                path: 'evaluate',
                name: 'vipEvaluate',
                component: () =>
                    import ('../views/vip/vip-evaluate.vue'),
                meta: { title: '评价管理', icon: 'example' }
            },
            {
                path: 'account',
                name: 'vipAccount',
                component: () =>
                    import ('../views/vip/vip-account.vue'),
                meta: { title: '账户信息', icon: 'example' }
            }
        ]
    },
    // 需求管理
    {
        path: '/requirement',
        component: Layout,
        redirect: '/requirement/list',
        name: 'requirement',
        meta: { title: '需求管理', icon: 'example' },
        children: [{
                path: 'list',
                name: 'requirementList',
                component: () =>
                    import ('../views/requirement/requirement-list.vue'),
                meta: { title: '需求列表', icon: 'example' }
            },
            {
                path: 'compare',
                name: 'requirementCompare',
                component: () =>
                    import ('../views/requirement/requirement-compare.vue'),
                meta: { title: '需求竞标列表', icon: 'example' }
            }
        ]
    },
    // 托管管理
    {
        path: '/hosting',
        component: Layout,
        redirect: '/hosting/list',
        name: 'hosting',
        meta: { title: '托管管理', icon: 'example' },
        children: [{
                path: 'list',
                name: 'hostingList',
                component: () =>
                    import ('../views/hosting/hosting-list.vue'),
                meta: { title: '托管列表', icon: 'example' }
            },
            {
                path: 'audit',
                name: 'hostingAudit',
                component: () =>
                    import ('../views/hosting/hosting-audit.vue'),
                meta: { title: '纠纷申请', icon: 'example' }
            },
            {
                path: 'record',
                name: 'hostingRecord',
                component: () =>
                    import ('../views/hosting/hosting-record.vue'),
                meta: { title: '托管预算增减记录', icon: 'example' }
            },

            {
                path: 'price',
                name: 'hostingPrice',
                component: () =>
                    import ('../views/hosting/hosting-price.vue'),
                meta: { title: '托管保证金明细', icon: 'example' }
            }
        ]
    },
    // 财务管理
    {
        path: '/finance',
        component: Layout,
        redirect: '/finance/deal',
        name: 'finance',
        meta: { title: '财务管理', icon: 'example' },
        children: [{
                path: 'deal',
                name: 'financeDeal',
                component: () =>
                    import ('../views/finance/finance-deal.vue'),
                meta: { title: '交易记录', icon: 'example' }
            },
            {
                path: 'sum',
                name: 'financeSum',
                component: () =>
                    import ('../views/finance/finance-sum.vue'),
                meta: { title: '统计查询', icon: 'example' }
            }
        ]
    },
    // 短信管理
    {
        path: '/message',
        component: Layout,
        redirect: '/message/list',
        name: 'message',
        meta: { title: '短信管理', icon: 'example' },
        children: [{
                path: 'list',
                name: 'messageList',
                component: () =>
                    import ('../views/message/message-list.vue'),
                meta: { title: '短信列表', icon: 'example' }
            },
            // {
            //     path: 'sum',
            //     name: 'messageSum',
            //     component: () =>
            //         import ('../views/message/message-sum.vue'),
            //     meta: { title: '短信统计', icon: 'example' }
            // }
        ]
    },
    // 收藏管理
    {
        path: '/collection',
        component: Layout,
        redirect: '/collection/list',
        name: 'collection',
        meta: { title: '收藏管理', icon: 'example' },
        children: [{
            path: 'list',
            name: 'collectionList',
            component: () =>
                import ('../views/collection/collection-list.vue'),
            meta: { title: '收藏列表', icon: 'example' }
        }]
    },
    // 前端管理
    {
        path: '/content',
        component: Layout,
        redirect: '/content/list',
        name: 'content',
        meta: { title: '前端管理', icon: 'example' },
        children: [{
                path: 'list',
                name: 'contentList',
                component: () =>
                    import ('../views/content/content-list.vue'),
                meta: { title: '文章列表', icon: 'example' }
            },
            {
                path: 'industry',
                name: 'contentIndustry',
                component: () =>
                    import ('../views/content/content-industry.vue'),
                meta: { title: '行业分类管理', icon: 'example' }
            },
            {
                path: 'datatype',
                name: 'contentDatatype',
                component: () =>
                    import ('../views/content/content-datatype.vue'),
                meta: { title: '字典管理', icon: 'example' }
            },
            {
                path: 'notice',
                name: 'contentNotice',
                component: () =>
                    import ('../views/content/content-notice.vue'),
                meta: { title: '通知公告', icon: 'example' }
            },
            {
                path: 'carousel',
                name: 'contentCarousel',
                component: () =>
                    import ('../views/content/content-carousel.vue'),
                meta: { title: '轮播管理', icon: 'example' }
            }
        ]
    },
    // 系统管理
    {
        path: '/system',
        component: Layout,
        redirect: '/system/user',
        name: 'system',
        meta: { title: '系统管理', icon: 'example' },
        children: [{
                path: 'user',
                name: 'systemUser',
                component: () =>
                    import ('../views/system/system-user.vue'),
                meta: { title: '用户管理', icon: 'example' }
            },
            {
                path: 'role',
                name: 'systemRole',
                component: () =>
                    import ('../views/system/system-role.vue'),
                meta: { title: '角色管理', icon: 'example' }
            },
            {
                path: 'auth',
                name: 'systemAuth',
                component: () =>
                    import ('../views/system/system-auth.vue'),
                meta: { title: '角色授权管理', icon: 'example' }
            },
            // {
            //     path: 'file',
            //     name: 'systemFile',
            //     component: () =>
            //         import ('../views/system/system-file.vue'),
            //     meta: { title: '附件管理', icon: 'example' }
            // },
            {
                path: 'menu',
                name: 'systemMenu',
                component: () =>
                    import ('../views/system/system-menu.vue'),
                meta: { title: '菜单管理', icon: 'example' }
            }
        ]
    },
    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true, meta: { title: '404' } }
]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router
